package com.lj.universalframework.utils

import com.scwang.smart.refresh.layout.SmartRefreshLayout

// <editor-fold desc="SmartRefreshLayout加载刷新">
/**
 * isRefresh 是否开启刷新
 * isLoad 是否开启加载更多
 * setOnRefreshListener 刷新回调
 * setOnLoadMoreListener 加载更多回调
 * isInitLoad 第一次是否默认刷新加载并第动画
 */
fun SmartRefreshLayout.loadRefresh(
    isRefresh: Boolean = true, isLoad: Boolean = false, isInitLoad: Boolean = true,
    setOnRefreshListener: () -> Unit, setOnLoadMoreListener: () -> Unit
): SmartRefreshLayout = apply {

    //开启自动加载功能（非必须)
    setEnableAutoLoadMore(isRefresh)
    //是否启用越界拖动（仿苹果效果）1.0.4-6
    setEnableOverScrollDrag(true)
    if (isRefresh) {
        setOnRefreshListener {
            //在刷新监听器上设置
            setOnRefreshListener()
        }
    }
    if (isLoad) {
        setOnLoadMoreListener {
            //加载更多侦听器
            setOnLoadMoreListener()
        }
    }
    //显示刷新动画并且触发刷新事件
    if (isInitLoad) {
        autoRefresh()
    }
}
// </editor-fold>